const mariadb = require('mariadb'); //引入mariadb插件链接数据裤
const { home_table } = require('./init')
const db = mariadb.createPool({ //数据库对象
    host: '106.53.136.143',
    port: '3306',
    user: 'root',
    password: '001016jiale',
    database: 'my_blog',
    connectionLimit: 5,
});

const connection = function (addSql) {
    return new Promise((resolve, reject) => {
        db.getConnection().then((conn, err) => {
            conn.query(addSql).then((data, err) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(data);
                }
                conn.release();
            }).catch(err => {
                conn.release();
                reject(err);
            })
        })
    });
};

function createTable(sql) {
    connection(sql, []);
}

createTable(home_table);

module.exports = {
    connection
};